package org.itboys.weixin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.itboys.framework.spring.controller.BaseController;
import org.itboys.fuzion.dto.FuzionMemberDto;
import org.itboys.fuzion.service.FuzionMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 微信会员中心
 * @author weisky
 *
 * 2016年4月18日
 */
@RestController 
@RequestMapping("/weixin/member") 
public class WeixinMemberController extends BaseController{

	@Autowired
	private FuzionMemberService fuzionMemberService;
	
	/**
	 * 会员的个人中心
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/memberCore") 
	public ModelAndView toMemberCore(Model model,
			HttpServletRequest request, HttpServletResponse response){
		Long memberId = (Long) request.getSession().getAttribute("memberId");
		if(memberId != null){
			FuzionMemberDto fm = fuzionMemberService.getByMemberId(memberId);
			model.addAttribute("member", fm);
			return new ModelAndView("/site/member");
		}
		return new ModelAndView("/error");
	}
}
